<template>
  <div class="message-input">
    <div class="input-wrapper">
      <!--      按回车键发送，输入框高度三行-->
      <el-input v-model="message"
                :autosize="true"
                class="input"
                type="textarea"
                placeholder="请输入你的问题"
                size="large"
                @keydown.enter.native="sendMessage">
      </el-input>
      <div class="button-wrapper">
        <el-button :disabled="isDisabled" type="primary" style="height: 38px" @click="sendMessage">
          <el-icon class="el-icon--left">
            <Position></Position>
          </el-icon>
          发送
        </el-button>
      </div>
    </div>
  </div>

</template>

<script setup>
import {ref} from "vue";
import {Position} from "@element-plus/icons-vue";
// 接收按钮是否置灰
defineProps({isDisabled: Boolean})
// 发送消息消息事件
const emit = defineEmits(['send'])
// 输入框内的消息
const message = ref('')
// 发送消息
const sendMessage = (event) => {
  event.preventDefault()
  emit('send', message.value)
  // 发送完清楚
  message.value = ''
}
</script>

<style scoped>
.message-input {
  padding: 20px;
  border-top: 1px solid rgba(0, 0, 0, .07);
  border-left: 1px solid rgba(0, 0, 0, .07);
  border-right: 1px solid rgba(0, 0, 0, .07);
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

.input-wrapper{
  display: flex;
  justify-content: space-between;
}

.button-wrapper {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-left: 10px;
}

:deep(.el-textarea__inner){
  height: 38px !important;
  line-height: 28px;
}
</style>